# 作者: 赵若云
# 2025年02月18日14时58分21秒
# 3478783573@qq.com


# num_list = []
# for i in range(100):
#     num_list.append(i)
# 上面三行式子相当于下面这一行
num_list = [x for x in range(10)]
print(num_list)
print('-' * 50)
# 两层for循环
a = [j for i in range(10) for j in range(i)]
print(a)

a = [[col * row for col in range(5)] for row in range(5)]
print(a)

print('-' * 50)

b = [i for j in a for i in j]  # 二维a变一维
print(b)

print('-' * 50)

# 只有if时
a = [x for x in range(10) if x % 2 == 0]  # 将只会筛选偶数
print(a)

print('-' * 50)

# if-else 的三元表达式
a = [x if x % 2 == 0 else x ** 2 for x in range(10)]
print(a)
